home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / share / ewl / examples / ewl_notebook_test.c < prev    next >
C/C++ Source or Header  |  2006-01-09  |  11KB  |  317 lines

  1. #include "ewl_test.h"
  2.  
  3. static Ewl_Widget *notebook_button;
  4.  
  5. static void __notebook_append_page(Ewl_Widget * w, void *ev_data,
  6.                         void *user_data);
  7. static void __notebook_prepend_page(Ewl_Widget * w, void *ev_data,
  8.                         void *user_data);
  9. static void __notebook_remove_visible_page(Ewl_Widget * w, void *ev_data,
  10.                         void *user_data);
  11.  
  12. static Ewl_Widget *button_aleft, *button_acenter, *button_aright;
  13. static Ewl_Widget *button_atop, *button_abottom;
  14. static Ewl_Widget *button_pleft, *button_pright, *button_ptop, *button_pbottom;
  15.  
  16. static void
  17. __destroy_notebook_test_window(Ewl_Widget * w, void *ev_data __UNUSED__,
  18.                         void *user_data __UNUSED__)
  19. {
  20.     ewl_widget_destroy(w);
  21.     ewl_callback_append(notebook_button, EWL_CALLBACK_CLICKED,
  22.                 __create_notebook_test_window, NULL);
  23. }
  24.  
  25. static void
  26. __notebook_change_alignment(Ewl_Widget * w, void *ev_data __UNUSED__,
  27.                         void *user_data)
  28. {
  29.     if (!ewl_radiobutton_is_checked(EWL_RADIOBUTTON(w)))
  30.         return;
  31.  
  32.     if (w == button_aleft)
  33.         ewl_notebook_tabs_alignment_set(user_data, EWL_FLAG_ALIGN_LEFT);
  34.     else if (w == button_acenter)
  35.         ewl_notebook_tabs_alignment_set(user_data,
  36.                         EWL_FLAG_ALIGN_CENTER);
  37.     else if (w == button_aright)
  38.         ewl_notebook_tabs_alignment_set(user_data, EWL_FLAG_ALIGN_RIGHT);
  39.     else if (w == button_atop)
  40.         ewl_notebook_tabs_alignment_set(user_data, EWL_FLAG_ALIGN_TOP);
  41.     else if (w == button_abottom)
  42.         ewl_notebook_tabs_alignment_set(user_data,
  43.                         EWL_FLAG_ALIGN_BOTTOM);
  44. }
  45.  
  46. static void
  47. __notebook_change_position(Ewl_Widget * w, void *ev_data __UNUSED__,
  48.                         void *user_data)
  49. {
  50.     if (!ewl_radiobutton_is_checked(w))
  51.         return;
  52.  
  53.     if (w == button_pleft)
  54.         ewl_notebook_tabs_position_set(user_data, EWL_POSITION_LEFT);
  55.     else if (w == button_pright)
  56.         ewl_notebook_tabs_position_set(user_data, EWL_POSITION_RIGHT);
  57.     else if (w == button_ptop)
  58.         ewl_notebook_tabs_position_set(user_data, EWL_POSITION_TOP);
  59.     else if (w == button_pbottom)
  60.         ewl_notebook_tabs_position_set(user_data, EWL_POSITION_BOTTOM);
  61. }
  62.  
  63. static void
  64. __notebook_create_main_page(Ewl_Widget * notebook)
  65. {
  66.     Ewl_Widget     *main_vbox;
  67.     Ewl_Widget     *tab;
  68.     Ewl_Widget     *text;
  69.     Ewl_Widget     *avbox, *alabel;
  70.     Ewl_Widget     *pvbox, *plabel;
  71.  
  72.     tab = ewl_text_new();
  73.     ewl_text_text_set(EWL_TEXT(tab), "Main");
  74.     ewl_widget_show(tab);
  75.  
  76.     main_vbox = ewl_vbox_new();
  77.     ewl_box_spacing_set(EWL_BOX(main_vbox), 10);
  78.     ewl_widget_show(main_vbox);
  79.  
  80.     text = ewl_text_new();
  81.     ewl_text_text_set(EWL_TEXT(text), "Main");
  82.     ewl_object_alignment_set(EWL_OBJECT(text), EWL_FLAG_ALIGN_CENTER);
  83.     ewl_container_child_append(EWL_CONTAINER(main_vbox), text);
  84.     ewl_widget_show(text);
  85.  
  86.     avbox = ewl_vbox_new();
  87.     ewl_object_alignment_set(EWL_OBJECT(avbox), EWL_FLAG_ALIGN_CENTER);
  88.     ewl_container_child_append(EWL_CONTAINER(main_vbox), avbox);
  89.     ewl_widget_show(avbox);
  90.  
  91.     alabel = ewl_text_new();
  92.     ewl_text_text_set(EWL_TEXT(alabel), "Tabs Alignment");
  93.     ewl_container_child_append(EWL_CONTAINER(avbox), alabel);
  94.     ewl_widget_show(alabel);
  95.  
  96.     button_atop = ewl_radiobutton_new();
  97.     ewl_button_label_set(EWL_BUTTON(button_atop), "Top");
  98.     ewl_container_child_append(EWL_CONTAINER(avbox), button_atop);
  99.     ewl_callback_append(button_atop, EWL_CALLBACK_VALUE_CHANGED,
  100.                 __notebook_change_alignment, notebook);
  101.     ewl_widget_show(button_atop);
  102.  
  103.     button_aleft = ewl_radiobutton_new();
  104.     ewl_button_label_set(EWL_BUTTON(button_aleft), "Left");
  105.     ewl_radiobutton_checked_set(button_aleft, 1);
  106.     ewl_container_child_append(EWL_CONTAINER(avbox), button_aleft);
  107.     ewl_radiobutton_chain_set(EWL_RADIOBUTTON(button_aleft),
  108.                   EWL_RADIOBUTTON(button_atop));
  109.     ewl_callback_append(button_aleft, EWL_CALLBACK_VALUE_CHANGED,
  110.                 __notebook_change_alignment, notebook);
  111.     ewl_widget_show(button_aleft);
  112.  
  113.     button_acenter = ewl_radiobutton_new();
  114.     ewl_button_label_set(EWL_BUTTON(button_acenter), "Center");
  115.     ewl_radiobutton_chain_set(EWL_RADIOBUTTON(button_acenter),
  116.                   EWL_RADIOBUTTON(button_aleft));
  117.     ewl_radiobutton_checked_set(button_acenter, 1);
  118.     ewl_container_child_append(EWL_CONTAINER(avbox), button_acenter);
  119.     ewl_callback_append(button_acenter, EWL_CALLBACK_VALUE_CHANGED,
  120.                 __notebook_change_alignment, notebook);
  121.     ewl_widget_show(button_acenter);
  122.  
  123.     button_aright = ewl_radiobutton_new();
  124.     ewl_button_label_set(EWL_BUTTON(button_aright), "Right");
  125.     ewl_radiobutton_chain_set(EWL_RADIOBUTTON(button_aright),
  126.                   EWL_RADIOBUTTON(button_acenter));
  127.     ewl_container_child_append(EWL_CONTAINER(avbox), button_aright);
  128.     ewl_callback_append(button_aright, EWL_CALLBACK_VALUE_CHANGED,
  129.                 __notebook_change_alignment, notebook);
  130.     ewl_widget_show(button_aright);
  131.  
  132.     button_abottom = ewl_radiobutton_new();
  133.     ewl_button_label_set(EWL_BUTTON(button_abottom), "Bottom");
  134.     ewl_radiobutton_chain_set(EWL_RADIOBUTTON(button_abottom),
  135.                   EWL_RADIOBUTTON(button_aright));
  136.     ewl_container_child_append(EWL_CONTAINER(avbox), button_abottom);
  137.     ewl_callback_append(button_abottom, EWL_CALLBACK_VALUE_CHANGED,
  138.                 __notebook_change_alignment, notebook);
  139.     ewl_widget_show(button_abottom);
  140.  
  141.     pvbox = ewl_vbox_new();
  142.     ewl_object_alignment_set(EWL_OBJECT(pvbox), EWL_FLAG_ALIGN_CENTER);
  143.     ewl_container_child_append(EWL_CONTAINER(main_vbox), pvbox);
  144.     ewl_widget_show(pvbox);
  145.  
  146.     plabel = ewl_text_new();
  147.     ewl_text_text_set(EWL_TEXT(plabel), "Tabs Position");
  148.     ewl_container_child_append(EWL_CONTAINER(pvbox), plabel);
  149.     ewl_widget_show(plabel);
  150.  
  151.     button_pleft = ewl_radiobutton_new();
  152.     ewl_button_label_set(EWL_BUTTON(button_pleft), "Left");
  153.     ewl_container_child_append(EWL_CONTAINER(pvbox), button_pleft);
  154.     ewl_callback_append(button_pleft, EWL_CALLBACK_VALUE_CHANGED,
  155.                 __notebook_change_position, notebook);
  156.     ewl_widget_show(button_pleft);
  157.  
  158.     button_pright = ewl_radiobutton_new();
  159.     ewl_button_label_set(EWL_BUTTON(button_pright), "Right");
  160.     ewl_radiobutton_chain_set(EWL_RADIOBUTTON(button_pright),
  161.                   EWL_RADIOBUTTON(button_pleft));
  162.     ewl_container_child_append(EWL_CONTAINER(pvbox), button_pright);
  163.     ewl_callback_append(button_pright, EWL_CALLBACK_VALUE_CHANGED,
  164.                 __notebook_change_position, notebook);
  165.     ewl_widget_show(button_pright);
  166.  
  167.     button_ptop = ewl_radiobutton_new();
  168.     ewl_button_label_set(EWL_BUTTON(button_ptop), "Top");
  169.     ewl_radiobutton_checked_set(button_ptop, 1);
  170.     ewl_radiobutton_chain_set(EWL_RADIOBUTTON(button_ptop),
  171.                   EWL_RADIOBUTTON(button_pright));
  172.     ewl_container_child_append(EWL_CONTAINER(pvbox), button_ptop);
  173.     ewl_callback_append(button_ptop, EWL_CALLBACK_VALUE_CHANGED,
  174.                 __notebook_change_position, notebook);
  175.     ewl_widget_show(button_ptop);
  176.  
  177.     button_pbottom = ewl_radiobutton_new();
  178.     ewl_button_label_set(EWL_BUTTON(button_pbottom), "Bottom");
  179.     ewl_radiobutton_chain_set(EWL_RADIOBUTTON(button_pbottom),
  180.                   EWL_RADIOBUTTON(button_ptop));
  181.     ewl_container_child_append(EWL_CONTAINER(pvbox), button_pbottom);
  182.     ewl_callback_append(button_pbottom, EWL_CALLBACK_VALUE_CHANGED,
  183.                 __notebook_change_position, notebook);
  184.     ewl_widget_show(button_pbottom);
  185.  
  186.     ewl_notebook_page_prepend(EWL_NOTEBOOK(notebook), tab, main_vbox);
  187. }
  188.  
  189. static void
  190. __notebook_generate_page(Ewl_Widget *notebook, int type)
  191. {
  192.     Ewl_Widget     *main_vbox, *hbox;
  193.     Ewl_Widget     *tab;
  194.     Ewl_Widget     *text;
  195.     Ewl_Widget     *button[3];
  196.     static int      num = 1;
  197.     char            label[20];
  198.  
  199.     snprintf(label, 20, "Page %i", num++);
  200.  
  201.     tab = ewl_text_new();
  202.     ewl_text_text_set(EWL_TEXT(tab), label);
  203.     ewl_widget_show(tab);
  204.  
  205.     main_vbox = ewl_vbox_new();
  206.     ewl_box_spacing_set(EWL_BOX(main_vbox), 10);
  207.     ewl_widget_show(main_vbox);
  208.  
  209.     text = ewl_text_new();
  210.     ewl_text_text_set(EWL_TEXT(text), label);
  211.     ewl_object_alignment_set(EWL_OBJECT(text), EWL_FLAG_ALIGN_CENTER);
  212.     ewl_container_child_append(EWL_CONTAINER(main_vbox), text);
  213.     ewl_widget_show(text);
  214.  
  215.     hbox = ewl_hbox_new();
  216.     ewl_box_spacing_set(EWL_BOX(hbox), 5);
  217.     ewl_object_padding_set(EWL_OBJECT(hbox), 0, 0, 20, 0);
  218.     ewl_object_alignment_set(EWL_OBJECT(hbox), EWL_FLAG_ALIGN_CENTER);
  219.     ewl_container_child_append(EWL_CONTAINER(main_vbox), hbox);
  220.     ewl_widget_show(hbox);
  221.  
  222.     button[0] = ewl_button_new();
  223.     ewl_button_label_set(EWL_BUTTON(button[0]), "Append Page");
  224.     ewl_container_child_append(EWL_CONTAINER(hbox), button[0]);
  225.     ewl_callback_append(button[0], EWL_CALLBACK_CLICKED,
  226.                 __notebook_append_page, notebook);
  227.     ewl_widget_show(button[0]);
  228.  
  229.     button[1] = ewl_button_new();
  230.     ewl_button_label_set(EWL_BUTTON(button[1]), "Prepend Page");
  231.     ewl_container_child_append(EWL_CONTAINER(hbox), button[1]);
  232.     ewl_callback_append(button[1], EWL_CALLBACK_CLICKED,
  233.                 __notebook_prepend_page, notebook);
  234.     ewl_widget_show(button[1]);
  235.  
  236.     button[2] = ewl_button_new();
  237.     ewl_button_label_set(EWL_BUTTON(button[2]), "Remove This Page");
  238.     ewl_object_alignment_set(EWL_OBJECT(button[2]), EWL_FLAG_ALIGN_CENTER);
  239.     ewl_container_child_append(EWL_CONTAINER(main_vbox), button[2]);
  240.     ewl_callback_append(button[2], EWL_CALLBACK_CLICKED,
  241.                 __notebook_remove_visible_page, notebook);
  242.     ewl_widget_show(button[2]);
  243.  
  244.     if (!type)
  245.         ewl_notebook_page_append(EWL_NOTEBOOK(notebook), tab, main_vbox);
  246.     else
  247.         ewl_notebook_page_prepend(EWL_NOTEBOOK(notebook), tab, main_vbox);
  248. }
  249.  
  250. static void
  251. __notebook_append_page(Ewl_Widget *w __UNUSED__, void *ev_data __UNUSED__,
  252.                         void *user_data)
  253. {
  254.     __notebook_generate_page(user_data, 0);
  255. }
  256.  
  257. static void
  258. __notebook_prepend_page(Ewl_Widget *w __UNUSED__, void *ev_data __UNUSED__,
  259.                         void *user_data)
  260. {
  261.     __notebook_generate_page(user_data, 1);
  262. }
  263.  
  264. static void
  265. __notebook_remove_visible_page(Ewl_Widget *w __UNUSED__, void *ev_data __UNUSED__,
  266.                             void *user_data)
  267. {
  268.     ewl_notebook_visible_page_remove(EWL_NOTEBOOK(user_data));
  269. }
  270.  
  271. void
  272. __create_notebook_test_window(Ewl_Widget * w, void *ev_data __UNUSED__,
  273.                         void *user_data __UNUSED__)
  274. {
  275.     Ewl_Widget     *notebook_win;
  276.     Ewl_Widget     *notebook_box;
  277.     Ewl_Widget     *notebook;
  278.  
  279.     notebook_button = w;
  280.  
  281.     notebook_win = ewl_window_new();
  282.     ewl_window_title_set(EWL_WINDOW(notebook_win), "Notebook Test");
  283.     ewl_window_name_set(EWL_WINDOW(notebook_win), "EWL Test Application");
  284.     ewl_window_class_set(EWL_WINDOW(notebook_win), "EFL Test Application");
  285.  
  286.     if (w) {
  287.         ewl_callback_del(w, EWL_CALLBACK_CLICKED,
  288.              __create_notebook_test_window);
  289.         ewl_callback_append(notebook_win, EWL_CALLBACK_DELETE_WINDOW,
  290.                 __destroy_notebook_test_window, NULL);
  291.     } else 
  292.         ewl_callback_append(notebook_win, EWL_CALLBACK_DELETE_WINDOW,
  293.                 __close_main_window, NULL);
  294.     ewl_widget_show(notebook_win);
  295.  
  296.     /*
  297.      * Create the main box for holding the widgets
  298.      */
  299.     notebook_box = ewl_vbox_new();
  300.     ewl_container_child_append(EWL_CONTAINER(notebook_win), notebook_box);
  301.     ewl_box_spacing_set(EWL_BOX(notebook_box), 10);
  302.     ewl_widget_show(notebook_box);
  303.  
  304.     notebook = ewl_notebook_new();
  305.     ewl_notebook_tabs_position_set(EWL_NOTEBOOK(notebook),
  306.                        EWL_POSITION_LEFT);
  307.     ewl_container_child_append(EWL_CONTAINER(notebook_box), notebook);
  308.     ewl_widget_show(notebook);
  309.  
  310.     __notebook_append_page(NULL, NULL, notebook);
  311.     __notebook_append_page(NULL, NULL, notebook);
  312.     __notebook_append_page(NULL, NULL, notebook);
  313.  
  314.     __notebook_create_main_page(notebook);
  315. }
  316.  
  317.